<?php
/**
 * Author:   tangxiaowen
 * Email:    846506584@qq.com
 * Date:     2019/3/12 0012
 * Describe: 用户信息管理类
 */

namespace app\index\controller;

class Member extends Base
{
    /**
     * 获取用户信息
     * @param string $param 用户ID|手机号
     * @param array $field 需要的字段
     * @return array
     */
    public function getUserInfo($param,$field = [])
    {
        return db('mem_info')->where('ID|Mobile',$param)->field($field)->find();
    }

    /**
     * 获取用户银行卡信息
     * @param int $userId 用户ID
     * @return array
     */
    public function getUserBankInfo($userId)
    {
        return db('renzen_bank')->where('UserID', $userId)->find();
    }

    /**
     * 根据用户ID获取用户信息及银行卡信息
     * @param int $userId 用户ID
     * @return array
     */
    public function getUserAndBankInfo($userId)
    {
        return db('mem_info')->alias('m')
            ->where(['m.ID' => $userId])
            ->join('xb_renzen_bank r','m.ID = r.UserID')
            ->find();
    }

    /**
     * 获取用户信息与银行卡及社交信息
     * @param int $userId 用户ID
     * @return array
     */
    public function getUserBankSocial($userId)
    {
        return db('mem_info')->alias('m')
            ->where(['m.ID' => $userId])
            ->join('xb_renzen_bank b','m.ID = b.UserID')
            ->join('xb_renzen_social s','m.ID =s.UserID')
            ->find();
    }

    /**
     * 根据用户DI获取用户紧急联系人
     * @param int $userId 用户ID
     * @return array
     */
    public function getUserEmergent($userId)
    {

        $data = db('renzen_social')->where(['UserID' => $userId])->find();
        if(!$data){
            return [];
        }

        $temp = [
            'firstName'     => $data['person_one'],
            'firstMobile'   => $data['person_one_mobile'],
            'firstRelation' => $data['r1'],
            'secondName'    => $data['person_two'],
            'secondMobile'  => $data['person_two_mobile'],
            'secondRelation'=> $data['r2'],
        ];

        return $temp;
    }

    /**
     * 获取用户魔蝎原始json数据
     * @param int $userId 用户ID
     * @return json
     */
    public function getMoXieJson($userId)
    {
        return db('moxie_origin')->where(['UserID' => $userId])->value('OriginData');
    }

    /**
     * 获取用户运营商报告信息
     * @param int $userId 用户ID
     * @return josn
     */
    public function getCarrierReportStr($userId)
    {
        return db('moxie_report')->where(['UserID' => $userId])->find();
    }

    /**
     * 获取用户放款次数
     * @param  int $userId 用户ID
     * @return int
     */
    public function getUserLoanNum($userId)
    {
        return db('loans_applylist')->where(['UserID' => $userId])->count('ID');
    }

    /**
     * 获取用户社交信息
     * @param int $userId 用户ID
     * @return array
     */
    public function getUserSocial($userId)
    {
        return db('renzen_social')->where(['UserID' => $userId])->find();
    }


}